package com.example.its2021606134chh.ETCModule;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.its2021606134chh.R;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * @ClassName: CarsRViewAdapter$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 26/7/2021$
 * @Version: 1.0
 */
public class CarsRViewAdapter extends RecyclerView.Adapter<CarsRViewAdapter.ViewHolder> {
    private List<Cars> list;
    public CarsRViewAdapter(List<Cars> list) {
        this.list = list;
    }

    @NonNull
    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_etc_recharge, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
        Cars cars = list.get(position);
        holder.tvETCID.setText(String.valueOf(position + 1));
        holder.tvETCCarID.setText(String.valueOf(cars.getCarID()));
        holder.tvETCCarRecharge.setText(String.valueOf(cars.getCarRecharge()));
        holder.tvETCUser.setText(String.valueOf(cars.getUser()));
        holder.tvETCTime.setText(String.valueOf(cars.getTime()));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvETCID, tvETCCarID, tvETCCarRecharge, tvETCUser, tvETCTime;
        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            tvETCID = itemView.findViewById(R.id.tvETCID);
            tvETCCarID = itemView.findViewById(R.id.tvETCCarID);
            tvETCCarRecharge = itemView.findViewById(R.id.tvETCCarRecharge);
            tvETCUser = itemView.findViewById(R.id.tvETCUser);
            tvETCTime = itemView.findViewById(R.id.tvETCTime);
        }
    }
}
